//
//  SinaVisitorVIew.m
//  oc微博
//
//  Created by 安陆与 on 16/1/14.
//  Copyright © 2016年 安陆与. All rights reserved.
//

#import "SinaVisitorVIew.h"
// 只要添加了这个宏，就不用带mas_前缀
 #define MAS_SHORTHAND
// 只要添加了这个宏，equalTo就等价于mas_equalTo
#define MAS_SHORTHAND_GLOBALS
// 这个头文件一定要放在上面两个宏的后面
#import "Masonry.h"


#import "AFHTTPSessionManager.h"

@interface  SinaVisitorVIew()

@property (nonatomic,weak) UIImageView *houseImage;

@property (nonatomic,weak) UILabel *messageLabel;

@property (nonatomic,weak) UIButton *loginBtn;

@property (nonatomic,weak) UIButton *registerBtn;

@property (nonatomic,weak) UIImageView *animationImage;

@end

@implementation SinaVisitorVIew


-(void)layoutSubviews{

    [super layoutSubviews];
    
    [self setupUI];
}

//设置布局
-(void)setupUI{
    
    self.backgroundColor = [UIColor colorWithWhite:237/255.0 alpha:1.0];
    
    [self setupAnimationImageView];

    
    [self setupHouseImageView];
    
    
    [self setupMessageLabel];
    
    [self setupLoginBtn];
    
    [self setupRegisterBtn];
    
    [self startAnimation];
}

//动画方法
-(void)startAnimation{

    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];

    NSValue *v = @(2* M_PI);
    
    animation.toValue = v;
    
    animation.repeatCount = MAXFLOAT;
    
    animation.duration = 20;
    
    animation.removedOnCompletion = NO;
    
    [self.animationImage.layer addAnimation:animation forKey:nil];
    

}

//添加旋转图片
-(void)setupAnimationImageView{

    UIImageView *animationImage = [[UIImageView alloc]init];
    
    [animationImage setImage:[UIImage imageNamed:@"visitordiscover_feed_image_smallicon"]];
    
    [animationImage sizeToFit];
    
    [self addSubview:animationImage];
    
    self.animationImage = animationImage;
    
    [animationImage makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.centerX);
        
        make.centerY.equalTo(self.centerY).offset(-50);
    }];

}


//添加小房子以及约束
-(void)setupHouseImageView{

    UIImageView *house = [[UIImageView alloc]init];
    [house setImage:[UIImage imageNamed:@"visitordiscover_feed_image_house"]];
    
    [self addSubview:house];
    
    self.houseImage = house;
    
    [house makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.centerX);
        make.centerY.equalTo(self.centerY).offset(-50);
    }];
    
}

//添加提示语
-(void)setupMessageLabel{
    
    UILabel *label = [[UILabel alloc]init];
    
    [self addSubview:label];

    label.text = @"关注一些人，回这里看看有什么惊喜  关注一些人，回这里看看有什么惊喜";
    
    label.textAlignment = 0;
    
    label.numberOfLines = 0;
    
    label.textColor = [UIColor darkGrayColor];
    
    
    self.messageLabel = label;
    
    
    //添加约束
    [label makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.houseImage.bottom).offset(20);
        
        make.centerX.equalTo(self.centerX);
        
        make.width.equalTo(257);
    }];

}

-(void)setupLoginBtn{

    UIButton *btn = [[UIButton alloc]init];
    
    [self addSubview:btn];

    
    [btn setBackgroundImage:[UIImage imageNamed:@"common_button_white_disable"] forState:(UIControlStateNormal)];
    [btn setTitle:@"登录" forState:(UIControlStateNormal)];
    
    [btn setTitleColor:[UIColor darkGrayColor] forState:(UIControlStateNormal)];
    
    //添加约束
    [btn makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(self.messageLabel.bottom).offset(10);
        make.left.equalTo(self.messageLabel.left);
        make.width.equalTo(100);
        make.height.equalTo(30);
    }];
    
    
    [btn addTarget:self.delegate action:@selector(didClickLogin) forControlEvents:(UIControlEventTouchUpInside)];
    
    self.loginBtn = btn;
    

}

//-(void)didClickLogin{
//
//    printf("点击代理登录了");
//}

-(void)setupRegisterBtn{

    UIButton *btn = [[UIButton alloc]init];
    
    [self addSubview:btn];
    
    [btn setBackgroundImage:[UIImage imageNamed:@"common_button_white_disable"] forState:(UIControlStateNormal)];
    [btn setTitle:@"注册" forState:(UIControlStateNormal)];
    
    [btn setTitleColor:[UIColor darkGrayColor] forState:(UIControlStateNormal)];
    
    //添加约束
    [btn makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.messageLabel.bottom).offset(10);
        make.right.equalTo(self.messageLabel.right);
        make.width.equalTo(100);
        make.height.equalTo(30);

    }];
    
    [btn addTarget:self.delegate action:@selector(didClickRegister) forControlEvents:(UIControlEventTouchUpInside)];
    
    self.registerBtn = btn;


}

//-(void)didClickRegister{
//    
//    printf("代理登录点击了");
//    
//
//}

@end











